//
//  Service+Equipment.m
//  xidian
//
//  Created by fengyn on 16/5/21.
//  Copyright © 2016年 lexingsoft. All rights reserved.
//

#import "Service+Equipment.h"

@implementation ServiceManager(Equipment)
///分页查询设备列表
+ (void)getAllEquipmentsWithPageIndex:(NSUInteger)pageIndex success:(void(^)(NSDictionary *data)) success failure:(void(^)(NSDictionary *data)) failure
{
    NSString *path = @"/equipment/page";
    const int countPer=20;
    NSDictionary *parameterDict=@{@"start":@(pageIndex*countPer),
                                  @"length":@(countPer)};
    [NetworkClient getRequest:path parameters:parameterDict NeedPrompt:YES success:^(id dataObject) {
        success(dataObject);
    } failure:^(id resultDict) {
        failure(resultDict);
    }];
}

///更新设备信息
+ (void)updateEquipmentInfoWithCode:(NSString *)equipmentCode infoDic:(NSDictionary *)infoDic success:(void(^)(NSDictionary *data)) success failure:(void(^)(NSDictionary *data)) failure
{
    NSString *path = [NSString stringWithFormat:@"/equipment/%@",equipmentCode];
    NSDictionary *parameterDict=infoDic;
    [NetworkClient putRequest:path parameters:parameterDict NeedPrompt:YES success:^(id dataObject) {
        success(dataObject);
    } failure:^(id resultDict) {
        failure(resultDict);
    }];
}

///根据设备code查询设备信息
+ (void)getEuqipmentInfoWithCode:(NSString *)equipmentCode success:(void(^)(NSDictionary *data)) success failure:(void(^)(NSDictionary *data)) failure
{
    NSString *path = @"/equipment/page";
    const int countPer=20;
    NSDictionary *parameterDict=@{@"start":@(0*countPer),
                                  @"length":@(countPer),
                                  @"equipmentSn":equipmentCode};
    [NetworkClient getRequest:path parameters:parameterDict NeedPrompt:YES success:^(id dataObject) {
        success(dataObject);
    } failure:^(id resultDict) {
        failure(resultDict);
    }];

}

#pragma mark - 报修信息管理
///创建报修信息
+ (void)createReportWithInfoDic:(NSDictionary *)infoDic success:(void(^)(NSDictionary *data)) success failure:(void(^)(NSDictionary *data)) failure
{
    NSString *path =[NSString stringWithFormat:@"/report"];
    NSDictionary *parameterDict=infoDic;
    [NetworkClient postRequest:path parameters:parameterDict NeedPrompt:YES success:^(id dataObject) {
        success(dataObject);
    } failure:^(id resultDict) {
        failure(resultDict);
    }];
}

///分页查询报修信息
+ (void)getAllReportsWithPageIndex:(NSUInteger)pageIndex euqipmentSn:(NSString *)euqipmentSn success:(void(^)(NSDictionary *data)) success failure:(void(^)(NSDictionary *data)) failure
{
    NSString *path = @"/report/page";
    const int countPer=20;
    NSDictionary *parameterDict=@{@"start":@(pageIndex*countPer),
                                  @"length":@(countPer),
                                  @"equipmentSn":euqipmentSn};
    [NetworkClient getRequest:path parameters:parameterDict NeedPrompt:YES success:^(id dataObject) {
        success(dataObject);
    } failure:^(id resultDict) {
        failure(resultDict);
    }];
}

///查看报修详情
+ (void)getReportInfoWithId:(NSString *)theId success:(void(^)(NSDictionary *data)) success failure:(void(^)(NSDictionary *data)) failure
{
    NSString *path =[NSString stringWithFormat:@"/report/%@",theId];
    NSDictionary *parameterDict=nil;
    [NetworkClient getRequest:path parameters:parameterDict NeedPrompt:YES success:^(id dataObject) {
        success(dataObject);
    } failure:^(id resultDict) {
        failure(resultDict);
    }];
}

///更新报修信息
+ (void)updateReportInfoWithId:(NSString *)theId infoDic:(NSDictionary *)infoDic success:(void(^)(NSDictionary *data)) success failure:(void(^)(NSDictionary *data)) failure
{
    NSString *path = [NSString stringWithFormat:@"/report/%@",theId];
    NSDictionary *parameterDict=infoDic;
    [NetworkClient putRequest:path parameters:parameterDict NeedPrompt:YES success:^(id dataObject) {
        success(dataObject);
    } failure:^(id resultDict) {
        failure(resultDict);
    }];
}

///获取处理方式
+ (void)getProcessMethodsSuccess:(void(^)(NSDictionary *data)) success failure:(void(^)(NSDictionary *data)) failure
{
    NSString *path =[NSString stringWithFormat:@"/common/standardChoices/processMethod/values"];
    NSDictionary *parameterDict=nil;
    [NetworkClient getRequest:path parameters:parameterDict NeedPrompt:YES success:^(id dataObject) {
        success(dataObject);
    } failure:^(id resultDict) {
        failure(resultDict);
    }];
}

///获取故障诊断
+ (void)getfailureDiagnosisSuccess:(void(^)(NSDictionary *data)) success failure:(void(^)(NSDictionary *data)) failure
{
    NSString *path =[NSString stringWithFormat:@"/common/standardChoices/failureDiagnosis/values"];
    NSDictionary *parameterDict=nil;
    [NetworkClient getRequest:path parameters:parameterDict NeedPrompt:YES success:^(id dataObject) {
        success(dataObject);
    } failure:^(id resultDict) {
        failure(resultDict);
    }];
}
@end
